export const detailColumns = [
  { title: 'ID', dataIndex: 'id' },
  { title: '创作者', dataIndex: 'username' },
  { title: '创建时间', dataIndex: 'created_at', valueType: 'date' },
  {
    title: '仓库地址',
    dataIndex: 'url',
    render: (v) => (
      <a target="_blank" href={v} rel="noreferrer">
        {v}
      </a>
    ),
    span: '3',
  },
  { title: '描述', dataIndex: 'desc' },
];

export const countList = [
  { field: 'optimize_count', title: '建议重构个数' },
  { field: 'time_used', title: '检测时长', unit: 'ms' },
  { field: 'file_count', title: '文件个数' },
  { field: 'func_count', title: '函数个数' },
  {
    field: 'other_count',
    title: '其他类型',
    tip: '除函数外的类型,可能是方法(classMethod 或 objectMethod)',
  },
];

export const formatUrl = (v, url) => {
  const cloneName = url.split('.')?.[1].replace('com', '');
  const viewPath = v.replace('/clone', '').replace(cloneName, '');
  const targetPath = url.replace('.git', '/blob/master') + viewPath;
  return { targetPath, viewPath };
};

export const complexityColumns = [
  { title: 'ID', dataIndex: 'id', width: 50 },
  {
    title: '整体复杂度',
    dataIndex: 'complexity',
    width: 100,
    tip: (
      <>
        该文件的整体复杂度,计算规则如下：
        <br />
        1.code eslint(向下取整)
        <br />
        2.代码行数 每600+5
        <br />
        3.外部引入包 0.5
        <br />
        4.函数的行数 每150+5
        <br />
        5.函数数量 1
        <br />
        6.函数参数 每5+5
        <br />
        7.函数个数 每15+5
      </>
    ),
    sorter: (a, b) => a.complexity - b.complexity,
  },
  {
    title: '基本复杂度',
    dataIndex: 'base_complexity',
    tip: '除行数分析外的其他复杂度',
    width: 100,
    sorter: (a, b) => a.base_complexity - b.base_complexity,
  },
  {
    title: '注释',
    dataIndex: 'comment_line',
    tip: '注释的代码行数',
    width: 70,
    sorter: (a, b) => a.comment_line - b.comment_line,
  },
  {
    title: '导入包',
    dataIndex: 'import_line',
    tip: '导入包的代码行数',
    width: 100,
    sorter: (a, b) => a.import_line - b.import_line,
  },
  {
    title: '文件地址',
    dataIndex: 'file_path',
    tip: '仓库中所占的位置',
    render: (v, { url }) => {
      const { targetPath, viewPath } = formatUrl(v, url);
      return (
        <a href={targetPath} target="_blank" rel="noreferrer">
          {viewPath}
        </a>
      );
    },
  },
  { title: '建议', dataIndex: 'advice', width: 100 },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    valueType: 'date',
    width: 100,
    sorter: (a, b) => {
      const aDate = new Date(a.created_at).getTime();
      const bDate = new Date(b.created_at).getTime();
      return aDate - bDate;
    },
  },
];

export const fileDetailsColumns = [
  {
    title: '名称',
    dataIndex: 'func_name',
    tip: '函数的名称',
    render: (v) => v.replaceAll("'", ''),
  },
  { title: '类型', dataIndex: 'func_type', tip: '函数的类型' },
  {
    title: '行数',
    dataIndex: 'func_line',
    tip: '函数行数',
    sorter: (a, b) => a.func_line - b.func_line,
  },
  {
    title: '参数个数',
    dataIndex: 'func_params',
    tip: '函数参数个数',
    sorter: (a, b) => a.func_params - b.func_params,
  },
];
